<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="套管外径(m)" prop="outerDiameter">
				<u-input :border="border" placeholder="请输入套管外径" v-model="model.outerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="套管内径(m)" prop="innerDiameter">
				<u-input :border="border" placeholder="请输入套管内径" v-model="model.innerDiameter" type="digit"></u-input>
			</u-form-item>
			<u-form-item  label-width="350"
				:label-position="labelPosition" label="钻孔长度(m)" prop="length">
				<u-input :border="border" placeholder="请输入钻孔长度" v-model="model.length" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;"  :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="套管环空体积" prop="volume">
					<span v-if="model.volume"> {{model.volume}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V = π/4 × (D1² - D2²) × L</view>
				<view class="u-item-desc">式中：V — 油管环空体积，单位 m³</view>
				<view class="u-item-desc">D1 — 套管外径，单位 m</view>
				<view class="u-item-desc">D2 — 套管内径，单位 m</view>
				<view class="u-item-desc">L — 钻孔长度，单位 m</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					outerDiameter: '',
					innerDiameter: '',
					length: '',
					volume: ''
				},
				rules: {
					outerDiameter: [{
						required: true,
						message: '请输入套管外径',
						trigger: 'blur'
					}],
					innerDiameter: [{
						required: true,
						message: '请输入套管内径',
						trigger: 'blur'
					}],
					length: [{
						required: true,
						message: '请输入钻孔长度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// Convert mm to m
						const D1 = parseFloat(this.model.outerDiameter) ;
						const D2 = parseFloat(this.model.innerDiameter) ;
						const L = parseFloat(this.model.length);
						
						// V = π/4 × (D1² - D2²) × L
						this.model.volume = (Math.PI / 4 * (Math.pow(D1, 2) - Math.pow(D2, 2)) * L).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>